import React, { useEffect } from 'react';
import { View, Text, StyleSheet } from 'react-native';

import { getInfo } from '../service/token';
import NavigationUtil from '../navigation/NavigationUtil';

export default function AuthLoadingScreen({ navigation }) {
  useEffect(() => {
    const bootstrapAsync = async () => {
      const info = await getInfo();
      if (!info) {
        navigation.navigate('Auth');
      } else {
        switch (info.role) {
          case 1:
            NavigationUtil.navigateWithWSInit(navigation, 'Manager');
            break;
          case 3:
            NavigationUtil.navigateWithWSInit(navigation, 'Worker');
            break;
          default:
            navigation.navigate('Auth');
            break;
        }
      }
    };
    bootstrapAsync();
  }, [navigation]);

  return (
    <View style={styles.container}><Text style={{ fontSize: 16 }}>加载中...</Text></View>
  );
}


const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
